from django.apps import AppConfig


class UsersAppConfig(AppConfig):
    name = "users"
    verbose_name = "用户"

    def ready(self):
        try:
            import users.signals  # noqa F401
        except ImportError:
            pass
        self.init_create_superuser()

    def init_create_superuser(self):
        from django.conf import settings
        try:
            self.models_module.User.objects.get(username=settings.INIT_CREATE_USERNAME)
        except self.models_module.User.DoesNotExist:
            self.models_module.User.objects.create_superuser(
                username=settings.INIT_CREATE_USERNAME, password=settings.INIT_CREATE_PASSWORD,
                email=f'{settings.INIT_CREATE_USERNAME}@onest.com',
            )
        except:
            ...
